﻿@{
    ViewData["Title"] = "Jquery";
}
<h1>Jquery</h1>

<button class="btn btn-secondary bg-success" id="btnGetData">获取数据</button>
<script>
    $(document).ready(() => {
        $("#btnGetData").click(() => {
            $.ajax({
                url: 'https://localhost:7111/api/jsonp/getdata',
                type: "get",
                dataType: "jsonp",
                jsonp: "callback",
                data: "callback=?",
                success: function (json) {
                    console.log(json);
                },
                error: function (e) {
                    console.log(e);
                }
            });
        });
    });
</script>

<button class="btn btn-secondary bg-success" id="btnGetData1">获取数据</button>
<script>
    $(document).ready(() => {
        $("#btnGetData1").click(() => {
           $.getJSON(
               'https://localhost:7111/api/jsonp/getdata?callback=?',
                function (data) {
                   console.log(data);
                }
           );
        });
    });
</script>


                    
<button class="btn btn-secondary bg-success" id="btnGetData2">获取数据</button>
<script>
    $(document).ready(() => {
        $("#btnGetData2").click(() => {
            $.ajax({
                url: "https://localhost:7111/api/jsonp/getData",
                dataType: "jsonp",
                type: "GET",
                jsonpCallback: 'processCallback',
                contentType: "application/json; charset=utf-8",
                success: function (result, status, xhr) {
                    console.log(result);
                },
                error: function (xhr, status, error) {
                    console.log("Result: " + status + " " + error + " " + xhr.status + " " + xhr.statusText)
                }
            });
        });
    });
</script>